package book.security;

import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.Signature;
import java.security.SignatureException;
import java.security.SignedObject;

public class SignedObjectTest {

	public static void main(String[] args) throws NoSuchAlgorithmException, InvalidKeyException, SignatureException, IOException {
		
		KeyPairGenerator gen = KeyPairGenerator.getInstance("DSA");
		gen.initialize(512);
		KeyPair keyPair = gen.generateKeyPair();
		Signature signature = Signature.getInstance(gen.getAlgorithm());
		
		byte[] data = "Data Signature".getBytes();
		SignedObject s = new SignedObject(data, keyPair.getPrivate(), signature);
//		byte[] sign = s.getSignature();
		System.out.println(s.verify(keyPair.getPublic(), signature));
	}
}
